include $(TOPDIR)/rules.mk

PKG_NAME:=webif-iw-lua-freeradius2
PKG_VERSION:=0.1
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_BUILD_DEPENDS:=+lua/host

include $(INCLUDE_DIR)/package.mk

#Build/Configure=$(Host/Configure) 

define Package/webif-iw-lua-freeradius2
  SECTION:=admin
  CATEGORY:=Administration
  SUBMENU:=webif
  DEPENDS:=+webif-iw-lua +freeradius2 +freeradius2-mod-chap +freeradius2-mod-files +freeradius2-mod-radutmp
  TITLE:=Freeradius2 Configuration and Settings Script in LUA
endef

define Build/Prepare
	$(call Build/Prepare/Default)
	$(CP) -a files $(PKG_BUILD_DIR)
	find $(PKG_BUILD_DIR)/files -name 'CVS' -o -name '.svn' -o -name '*~' | $(XARGS) rm -rf
endef

define Build/Configure
endef

define Build/Compile
	find $(PKG_BUILD_DIR)/files -type f -name '*.lua' -exec $(STAGING_DIR_HOST)/bin/luac -s -o {} {} \;
endef

define Package/webif-iw-lua-freeradius2/install
	$(CP) -a $(PKG_BUILD_DIR)/files/* $(1)/
#	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/etc/init.d/radiusd $(1)/etc/init.d/radiusd
#	$(INSTALL_DATA) $(PKG_BUILD_DIR)/files/etc/* $(1)/etc/
	$(INSTALL_DIR) $(1)/www/cgi-bin/webif/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/www/cgi-bin/webif/* $(1)/www/cgi-bin/webif/
	$(INSTALL_DIR) $(1)/usr/lib/lua/lua-xwrt
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/usr/lib/lua/lua-xwrt/freerad_users.lua $(1)/usr/lib/lua/lua-xwrt/freerad_users.lua
endef

$(eval $(call BuildPackage,webif-iw-lua-freeradius2))
